<%@page import="java.util.List"%>
<%@page import="entities.Category"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
List<Category> categories = (List<Category>) request.getAttribute("categories");
List<Category> cats = (List<Category>) request.getAttribute("cats");
String parentId = (String) request.getAttribute("parentId");
String ids = "";
for (Category category : categories) {
	if (!ids.isEmpty()) ids += ",";
	ids += category.getId();
}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<link href="/admin/plugins/forms/select/select2.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="/admin/js/jquery.tablednd.js"></script>
<script type="text/javascript" src="/admin/plugins/forms/select/select2.min.js"></script>

<script type="text/javascript" src="/admin/js/custom/category_arrange.js"></script>

				<jsp:include page="/admin/elements/heading_panel.jsp" />

                <!-- Build page from here: -->
                <div class="row-fluid">
					<div class="span12">
						<jsp:include page="/admin/elements/message_box.jsp" />

						<form method="get" class="form-horizontal">
							<div class="form-row row-fluid">
								<div class="span6">
									<select id="parentId" name="parentId" class="nostyle"
										placeholder="Select Parent Category" style="width: 100%;">
										<option></option>
										<%
											for (int i = 0; i < cats.size(); i++) {
										%>
										<option value="<%=cats.get(i).getId()%>"
											<%=parentId != null
										&& parentId.equalsIgnoreCase(cats.get(i).getId()) ? "selected=\"selected\""
										: ""%>>
											|<%
											for (int j = 2; j <= cats.get(i).getLevel(); j++) {
										%>&nbsp;&nbsp;|<%
											}
										%>___
											<%=cats.get(i).getName()%>
											(<%=cats.get(i).getLevel()%>)
										</option>
										<%
											}
										%>
									</select>
								</div>
								<div class="span6">
									<button class="btn btn-info" type="submit">Select</button>
								</div>
							</div>
						</form>


		<div class="box">
                        	<div class="title">
                                <h4>
                                    <span class="icon16 icomoon-icon-list-view"></span>
                                    <span>Category List</span>
                                </h4>
                                <a href="#" class="minimize">Minimize</a>
                            </div>
                            
                            <div class="content noPad">
                                <table class="responsive table table-bordered sortable" id="drap-table">
                                    <thead>
                                      <tr>
                                      	<th width="20px;"></th>
                                        <th>Id</th>
                                        <th>Title</th>
                                        <th>Parent</th>
                                        <th>Status</th>
                                        <th>Actions</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <% for (int i = 0; i < categories.size(); i++) { %>
                                      <tr  id="<%=categories.get(i).getId()%>">
                                      	<td class="icon16 icomoon-icon-move"></td>
                                        <td><%=categories.get(i).getId() %></td>
                                        <td><%=categories.get(i).getName() %></td>
                                        <td><%=categories.get(i).getParentId() %></td>
                                        <td>
                                        	<%
											switch (categories.get(i).getStatus()) {
												case 0: 
													%>Inactive<%
													break;
												case 1:
													%>Pending<%
													break;
												case 2:
													%>Active<%
													break;
												default:
													break;
											}
											%>
                                        </td>
                                        <td>
                                            <div class="controls center">
                                                <a href="/admin/category/edit/<%=categories.get(i).getId()%>" title="Edit Category" class="tip"><span class="icon12 icomoon-icon-pencil"></span></a>
                                                <a href="/admin/category/delete/<%=categories.get(i).getId()%>" title="Remove Category" class="tip delete"><span class="icon12 icomoon-icon-remove"></span></a>
                                            </div>
                                        </td>
                                      </tr>
                                      <% } %>
                                    </tbody>
                                </table>
                            </div>
						</div><!-- End .box -->
						
						<form class="form-horizontal" method="post">
                            <input type="hidden" name="ids" value="<%=ids %>" id="ids">
                            <button class="btn btn-info" type="submit" disabled="disabled" id="submit-order">
								<span class="icon16 icomoon-icon-loop white"></span>
								Save Change
							</button>
						</form>
						
					</div><!-- End .span6 -->

				</div><!-- End .row-fluid -->
                
<jsp:include page="/admin/layouts/footer.jsp" />